TypeForm: Enable by default#21262
Conversation
...removing the need to use --enable-incomplete-feature=TypeForm
This comment has been minimized.
This comment has been minimized.
|
|
||
| [case testRecognizesParameterizedTypeFormInAnnotation] | ||
| # flags: --python-version 3.14 --enable-incomplete-feature=TypeForm | ||
| # flags: --python-version 3.15 |
There was a problem hiding this comment.
hm do we already support 3.15 enough for this to make sense? The test uses typing_extensions anyway so I'm not sure why it needs to pin a version at all.
There was a problem hiding this comment.
The test uses typing_extensions anyway so I'm not sure why it needs to pin a version at all.
If it's OK for the test to (A) continue to use typing_extensions, then I agree that the --python-version 3.15 doesn't make a lot of sense.
OTOH, if it would be more conventional in tests to (B) use the typing version, then I think --python-version 3.15 becomes necessary.
I'll take a look in the next few days to see what other tests are doing to choose whether to do (A) or (B).
There was a problem hiding this comment.
We don't run 3.15 in CI, and may potentially not run it for another few months, so we should use 3.14 for now. It will be easy to mass update these tests to typing in the future (as we did with other type system features).
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
ilevkivskyi
left a comment
There was a problem hiding this comment.
Thanks! It is probably better to put this in v2.1 to be safe. I will leave this up to @JukkaL
There was a problem hiding this comment.
In #20946, I kept the --python-version 3.14 flags, maybe it makes sense to keep them?
|
We'll likely have mypy 2.1 out pretty soon afterwards, so we can wait for 2.1. |
|
Hm, our daily benchmark shows this PR caused 2% slow-down on self-check. Taking into account mypy itself doesn't use I guess the slow-down is because we call I think we should only interpret an expression as type whenever a |
|
I’ll take a look at the performance on selfcheck in the next few days. The TypeForm-related code already has “cache-hit” / “cache-miss” style performance counters plus a script to interpret them, which should be useful for investigation. |
|
Btw, I briefly looked at the current I don't know how hard it is, but I think the optimal way would be to fix the
For the last items you don't need to do an extra visit, simply record the presence of |
|
Don't know how much it will help but I noticed an easy opportunity to get rid of one of the two regexes: #21459. Also looking into the second one a bit to see if we can get a better heuristic. |
|
Rearranged the code a bit more based on some observations about strings appearing in mypy itself. If the regression is really driven by the string matching in |
To be clear, I don't think it is the main factor, but likely a significant factor. I think it may be necessary to do most of the things I mentioned above to make the regression go away ~completely. |
IIRC the only reason there’s logic in the semantic analyzer (and not just only in the TypeChecker) is because string literals are sometimes type annotations and TypeChecker doesn’t have enough info to resolve all references that could occur in a string context. In particular locally defined classes are thrown out by the time TypeChecker gets to look at an expression. I’m still tracking the task of optimizing performance related to this thread. Last week I was finishing up items for work as I was transitioning out into parental leave. Hopefully I should have some more bandwidth over the next few days. |
Btw if someone can benchmark this PR on something unrelated, like |
...removing the need to use --enable-incomplete-feature=TypeForm
REVIEWER NOTES: